﻿using System;
using System.Collections.Generic;

using E.BLL;
using E.Model;
using E.Web.UI.Page;

using X.Pager;
using X.Pager.List;
using X.Common;

namespace E.Web.Teacher.exam
{
    public partial class ScoreInquiry : TeacherBasePage
    {
        public IList<DictAreaModel> areaList;
        public IList<ShortScoreModel> scoreList;
        public Dictionary<int, string> certificateList;
        public IList<CourseCategoryModel> cc_list;
        public IDictionary<int, string> scoreCategoryList;
        public string act;
        public string userName, fromDate, toDate;
        public string classCode;
        public int areaid;
        public int certificateID;
        public int courseID;
        public string startFromDate = "";
        public string startToDate = "";
        public int courseCategoryID;
        public string loginid;

        protected override void ShowPage()
        {
            areaList = GetTeacherAreaList(teacherid);
            certificateList = GetCertificateList();
            cc_list = GetCourseCategoryList();

            act = XRequest.GetString("act");
            userName = XRequest.GetString("UserNameTxt");
            loginid = XRequest.GetString("LoginIDTxt");
            classCode = XRequest.GetString("ClassCodeTxt");
            courseID = XRequest.GetInt("CourseSlt", -1);
            certificateID = XRequest.GetInt("CertificateSlt", -1);
            courseCategoryID = XRequest.GetInt("CategorySlt", -1);

            if (areaList.Count == 1)
            {
                areaid = areaList[0].ID;
            }
            else
            {
                areaid = XRequest.GetInt("AreaSlt", -1);
            }
            
            ExamBLL bll = new ExamBLL();
            scoreCategoryList = bll.GetInputScoreCategoryList();

            InitSearchDateTime();

            if (ispost || act == "s")
            {
                SearchScoreModel model = new SearchScoreModel();
                model.LoginID = loginid;
                model.UserName = userName;
                model.AreaID = areaid;
                model.CertificateID = certificateID;
                model.CourseID = courseID;
                model.ClassCode = classCode;
                model.StartFromDate = startFromDate;
                model.StartToDate = startToDate;
                model.CourseCategoryID = courseCategoryID;
                model.EntryFromDate = fromDate;
                model.EntryToDate = toDate;

                if (authority != E.Enum.EnumTeacherAuthority.Admin)
                {
                    model.TeacherID = teacherid;
                }
                else
                {
                    model.TeacherID = -1;
                }

                ScoreListModel listModel = new ScoreListModel();

                CheckPageIndexValue(XRequest.GetInt("s", 1) - 1, XRequest.GetInt("g", 0), XRequest.GetInt("z", customerPageSize));

                listModel = bll.SearchScoreByCondition(model, customerPageSize, pageIndex);
                if (listModel.TotalCount > 0)
                {
                    count = listModel.TotalCount;
                    //count = 200000;
                    scoreList = listModel.List;
                    PagerBase pager = new ListPager(count, pageIndex, currentPgGroup, customerPageSize, defaultPagesInGroup);

                    Dictionary<string, string> parms = new Dictionary<string, string>();
                    parms.Add("act", act);
                    parms.Add("LoginIDTxt", loginid);
                    parms.Add("UserNameTxt", userName);
                    parms.Add("ClassCodeTxt", classCode);
                    parms.Add("AreaSlt", areaid.ToString());
                    parms.Add("CourseSlt", courseID.ToString());
                    parms.Add("CertificateSlt", certificateID.ToString());
                    parms.Add("CategorySlt", courseCategoryID.ToString());
                    parms.Add("StartFromDateTxt", startFromDate);
                    parms.Add("StartToDateTxt", startToDate);
                    parms.Add("FromDateTxt", fromDate);
                    parms.Add("ToDateTxt", toDate);
                    mypager = pager.DrawPager("selfpager", parms);
                }
                //}
            }

        }

        private void InitSearchDateTime()
        {
            try
            {
                if (!XRequest.GetString("StartFromDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("StartFromDateTxt"));
                    startFromDate = XRequest.GetString("StartFromDateTxt");
                }

                if (!XRequest.GetString("StartToDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("StartToDateTxt"));
                    startToDate = XRequest.GetString("StartToDateTxt");
                }
                if (!XRequest.GetString("FromDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("FromDateTxt"));
                    fromDate = XRequest.GetString("FromDateTxt");
                }

                if (!XRequest.GetString("ToDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("ToDateTxt"));
                    toDate = XRequest.GetString("ToDateTxt");
                }
            }
            catch (Exception ex)
            {

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
